/*
 * Copyright 2000-2020 ALPHA LAB.Inc All Rights Reserved.
 */
package com.alphalab.framework.domain;

/**
 * 数据模型状态工具类，用来标记对象的状态以便服务端判断执行更新、删除等操作.
 * @author allen 
 * @version 1.0.0 2017年6月27日
 */
public final class DataModelState {
	
	/**
	 * 默认.
	 */
    public static final int DEFAULT = 1;
    /**
     * 新增.
     */
    public static final int NEW = 4;
    /**
     * 修改.
     */
    public static final int MODIFY = 8;
    /**
     * 删除.
     */
    public static final int DELETE = 2;
    /**
     * 选中.
     */
    public static final int SELECTED = 16;
    /**
     * 活动.
     */
    public static final int CHILD_MODIFY = 64; 

    /**
     * 不允许外部实例化、被继承.
     */
	private DataModelState() {
		
	}

	/**
	 * isDefault.
	 * @param curState 状态
	 * @return boolean
	 */
	public static boolean isDefault(final int curState) {
		return curState == DataModelState.DEFAULT;
	}

	/**
	 * isNew.
	 * @param curState 状态
	 * @return boolean
	 */	
	public static boolean isNew(final int curState) {
		return curState == DataModelState.NEW;
	}

	/**
	 * isModify.
	 * @param curState 状态
	 * @return boolean
	 */	
	public static boolean isModify(final int curState) {
		return curState == DataModelState.MODIFY;
	}

	/**
	 * isModifySub.
	 * @param curState 状态
	 * @return boolean
	 */	
	public static boolean isModifySub(final int curState) {
		return curState == DataModelState.CHILD_MODIFY;
	}

	/**
	 * isDelete.
	 * @param curState 状态
	 * @return boolean
	 */	
	public static boolean isDelete(final int curState) {
		return curState == DataModelState.DELETE;
	}

	/**
	 * isSelected.
	 * @param curState 状态
	 * @return boolean
	 */	
	public static boolean isSelected(final int curState) {
		return curState == DataModelState.SELECTED;
	}

	/**
	 * isChange.
	 * @param curState 状态
	 * @return boolean
	 */	
	public static boolean isChange(final int curState) {
		return isNew(curState) || isDelete(curState) || isModify(curState)
				|| isModifySub(curState);
	}

	/**
	 * isTrue.
	 * @param curState 对象状态
	 * @param constState 变量状态
	 * @return boolean
	 */	
	public static boolean isTrue(final int curState, final int constState) {
		return curState == constState || (curState & constState) > 0;
	}

}
